// pages/my/consumption-record/consumption-record.js
const request = require('../../../../../utils/request')
const common  = require('../../../../../utils/common')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        //选项卡
        tabActiveId: 0,
        status: 1,
        list:[],
        isLastPage:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getList()
    },
    onShow() {
    },
    getList() {
        let _this = this
        let isLastPage = this.data.isLastPage
        request._post('/api?method=user.userAccount', {
            type: this.data.tabActiveId,
            page:this.data.page
        }).then(res => {
            if(res.data.list.length  == 0) {
                isLastPage = true
            } else {
                isLastPage = false
            }
            
            res.data.list.forEach(function(obj,index) {
                obj.ctime = common.formatDate(obj.ctime)
            })
           
            _this.setData({
                list:_this.data.list.concat(res.data.list),
                isLastPage
            })
        })
    },
    /**
     * 选项卡
     */
    tabClick(e) {
        const d = e.currentTarget.dataset;
        this.setData({
            tabActiveId: d.id,
            list:[],
            page:1,
            isLastPage:false
        })
        this.getList()
    },
    // 上拉加载
    onReachBottom: function () {
        let page = this.data.page
        if(this.data.isLastPage) {
            return
        }
        page++
        this.setData({
            page
        })
        this.getList()
    },
    
})